import { BaseWindow } from "../../../../component/window/BaseWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { EOperOption } from "../../../../../Message/Game/EOperOption";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Cache } from "../../../cache/Cache";
import { QuickBuyListWindow } from "../../common/QuickBuyListWindow";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SPublicMiniPlayer } from "../../../../../Message/Public/SPublicMiniPlayer";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { Global } from "../../../../../com/gengine/global/Global";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
type int = number;
//class GuildWelcomeNewMemberWindow
    
    export  class GuildWelcomeNewMemberWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(475, 160);
            this.title = Language.getString(57207);
            this.titleHeight = 28;
            ObjCreate.createBg(20, 40, 435, 105, this);
            this._tipTxt = ObjCreate.createGTextField("", 25, 52, 300, 20, this, GlobalStyle.textFormat2);
            this._expBtn = ObjCreate.createGButton(Language.getString(57208), 25, 85, 130, 24, this);
            this._expBtn.name = "exp";
            this._expBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._moneyBtn = ObjCreate.createGButton(Language.getString(57209), 170, 85, 130, 24, this);
            this._moneyBtn.name = "money";
            this._moneyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._propBtn = ObjCreate.createGButton(Language.getString(57210), 320, 85, 130, 24, this);
            this._propBtn.name = "prop";
            this._propBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._checkBox = ObjCreate.createCheckBox(Language.getString(90093), 25, 115, 100, 28, this);
            this._checkBox.addEventListener(flash.events.Event.CHANGE, this.onChangeHandler);
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var btnName: string;
            var option: EOperOption;
            var ary: Array<any>;
            var isChooseFlower: Function;

            var loc1;
            option = null;
            ary = null;
            e = arg1;
            btnName = (e.target as GButton).name;
            if (btnName != "exp") 
            {
                if (btnName != "money") 
                {
                    if (btnName == "prop") 
                    {
                        isChooseFlower = (arg1: ItemData): Boolean
                        {
                            if (ItemsUtil.isFlower(arg1) && arg1.effect == 1) 
                            {
                                return true;
                            }
                            return false;
                        }
                        option = EOperOption.convert(EOperOption._EOperOptionProp);
                        ary = Cache.instance.pack.backPackCache.getItemsByJudge(isChooseFlower);
                        if (ary.length == 0) 
                        {
                            QuickBuyListWindow.instace.quickUpdateData(ECategory._ECategoryProp, EProp._EPropFlower);
                            QuickBuyListWindow.instace.show();
                        }
                    }
                }
                else 
                {
                    option = EOperOption.convert(EOperOption._EOperOptionMoney);
                }
            }
            else 
            {
                option = EOperOption.convert(EOperOption._EOperOptionExp);
            }
            if (this._miniPlayer) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildSendWelcome, {"option": option, "toPlayerName": this._miniPlayer.name}));
            }
            return;
        }

        public updateWelcome(arg1: SPublicMiniPlayer): void
        {
            this._miniPlayer = arg1;
            if (arg1) 
            {
                this._tipTxt.text = Language.getStringByParam(57211, arg1.name);
            }
            return;
        }

        /* internal  */onChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            PulseSharedObject.save("GuildWelcomeNew", this._checkBox.selected);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            arg1 = (Global.stage.stageWidth - this.width) / 2;
            arg2 = (Global.stage.stageHeight - this.height) / 2 - 100;
            super.show(arg1, arg2);
            return;
        }

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_expBtn: GButton;

        /* internal */ /* var */_moneyBtn: GButton;

        /* internal */ /* var */_propBtn: GButton;

        /* internal */ /* var */_checkBox: GCheckBox;

        /* internal */ /* var */_miniPlayer: SPublicMiniPlayer;
    }
